import React, { useState, useEffect } from 'react'
import { View, RichText } from '@tarojs/components'
import { AtList, AtListItem, AtButton, AtToast } from "taro-ui"
import Taro, {  useShareAppMessage,useShareTimeline } from '@tarojs/taro'
import ToLogin from '../../compontents/toLogin'
import api from '../../http/api'
import lhTool from 'lh-tool'

import './index.less'
import "taro-ui/dist/style/components/list.scss";
import "taro-ui/dist/style/components/icon.scss";
import "taro-ui/dist/style/components/modal.scss";
import "taro-ui/dist/style/components/button.scss";
import "taro-ui/dist/style/components/toast.scss";


export default (props: any) => {
  const id:any = props.tid.split('id=')[1].split('&')[0]
  const [data,setData]:any = useState({"id":34,"uSchoolId":1,"src":"https://static.zhongningwenhua.com/uniSchool/upload/33eab9e2ee7edaaef3073cb15d716509.png","title":"我敢闯，我会创","intro":"2020大学生第十一届创新创业大赛强势来袭","activeTime":"2020-12-31T13:03:32.000Z","address":"温泉校区学术报告厅","content":"<p style=\"text-align:center;\"><br></p><p style=\"text-align:center;\">我敢闯，我会创<br><br>2020大学生第十一届创新创业大赛强势来袭！<br><br>创新创业的巅峰对决，全面打响<br><br>凛冽的冬风吹不灭创新的热情<br>前路的未知动不了创业的决心<br>舞台的大小定不下我们的未来<br><br>大家对创新创业的热情炙热，激情与热血在这个严寒的冬天燃烧<br>所有选手蓄积满格能量<br>令人热血沸腾<br>睿智创新始于心&nbsp;，激情创业践于行<br><br>本次大赛以帮助大学生了解创业知识为目的，激发大学生创新创业的热情，提高自主创业的能力，营造良好的创业氛围，带动更多的大学生投身自主创业实践的行列，引导大学生树立正确的就业观和价值观。<br><br>观看此次比赛，我相信你能收获颇多。<br>创业大舞台，有你更精彩。<br>如果你想了解更多创新创业方面的知识，就快来参加本次活动吧<br><br>活动时间:12月8日晚19点<br>活动地点:温泉校区学术报告厅<br>活动对象:全校学生<br><br>咸安校区的同学们也不用担心哦，是有校车可以接送过来的。<br>请大家佩戴好口罩做好安全防护措施。<br><br>——湖北科技学院学生会宣<o:p></o:p></p><p style=\"text-align:center;\"><br></p>","type":2,"manageId":11,"isGrounding":1,"publishTime":"2020-12-27T13:07:33.000Z","ord":0})
  useEffect(()=>{
    api.version().then((res:any)=>{
      const version = res.data
      if (version === 1) {
        api.activeDetail({
          id:id,
        }).then((res:any)=>{
          const _data =  res.data
          _data.content = _data.content.replace(/<img/g,"<img style='width:100%'")
          setData(_data)
        })
      }
    })
    
  },[])
  useShareAppMessage(res => {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: `U你校园广场详情 ${data.title}`,
      path: `/pages/newsDetail/index?id=${id}`
    }
  })
  useShareTimeline(()=>{
    return {
      title: `U你校园广场详情 ${data.title}`,
      path: `/pages/newsDetail/index?id=${id}`
    }
  })
  return (
    <View className='activeDetail'>
      <ToLogin url='/pages/activeDetail/index'></ToLogin>
      <View className='title'>
      <View className='txt'>{data.title}</View>
        <View className='time'>发布时间：{lhTool.formatDate.format(new Date(data.publishTime),'yyyy/MM/dd hh:mm:ss')}</View>
        <View className='time'>活动地址：{data.address}</View>
        <View className='time'>活动时间：{lhTool.formatDate.format(new Date(data.activeTime),'yyyy/MM/dd hh:mm:ss')}</View>
      </View>
      <View className='content'>
        <RichText nodes={data.content}/>
      </View>  
      {/* <View className='getCard'>
        <View className='shareW'>
          <View className='at-icon at-icon-share'></View>
          <View className='share'>分享</View> 
        </View>
      </View> */}
    </View>
  )
}
